package interviewQuestions;

/**
 * 数字转字母
 * 1-A、2-B、26-Z、27-AA、703-AAA
 *
 * */
public class IntToZ {


    public static String reserve(String str){
        int len = str.length();
        char[] chars = str.toCharArray();
        for (int i = 0,j=len-1; i < j; i++,j--) {
            char t = chars[i];
            chars[i] = chars[j];
            chars[j] = t;
        }
        return String.valueOf(chars);
    }

    public static String intToZ(int num){
        String str = "";

        while(num != 0){
            char a = (char) (num % 26 + 64);
            str += String.valueOf(a);
            num /= 26;
        }
        // 反转字符串

        return reserve(str);
    }

    public static void main(String[] args) {
        String s = intToZ(708);
        System.out.println(s);
    }

}
